<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

// @TODO: Get results only where they are set to active

class Giaovien_model extends CI_Model
{
	protected $_table;	    
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->helper('date');
	}
		
	/**
	 * Get all Categories
	 *
	 * @access	public
	 * @return 	object	Categories
	 */
	function get_all_giaovien($limit, $start)
	{
		$this->db->select('giaovien.*,khoa.id as khoaid, khoa.makhoa, khoa.tenkhoa');
		$this->db->from('giaovien','khoa');
		$this->db->join('khoa', 'khoa.id = giaovien.id_khoa');
		
		$this->db->order_by('khoa.tenkhoa','ASC');
		$this->db->limit($limit, $start);
		$query = $this->db->get();
		return $query->result_array();
	}	
	
	function get_tenkhoa()
	{
		$this->db->select('id, makhoa, tenkhoa');
		$this->db->from('khoa');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	// --------------------------------------------------------------------
	public function get_giaovien_info($id)
	{
		$this->db->select('*');
		$this->db->from('giaovien');
		$this->db->where('id', $id);
		$query = $this->db->get();
		return $query->row();
	}
	
	public function tach_tengv($tengv)
	{
		$tenmoi = explode(" ",$tengv);
		return $tenmoi;
	}
	
	
	function delete_giaovien($id)
	{
		$fields = array(
			'status' 			=> 0,
			'deleted' 			=> 1,
		);
		$this->db->set($fields);
		$this->db->where('id', $id);
		$this->db->update('giaovien');
	}
	
	public function change_status_giaovien($id = null,$status = 0)
	{
		$data = array
				(
					'status'=> $status
				);
		$this->db->where('id',$id);
		$this->db->update('giaovien',$data);		
	}
	
	
	public function search_data($keyword)
	{
		$this->db->select('giaovien.*, khoa.id as khoacid, khoa.makhoa');
		$this->db->from('giaovien','khoa');
		$this->db->join('khoa','khoa.id = giaovien.id_khoa');
		$this->db->like('giaovien.magv', $keyword);
		$this->db->or_like('giaovien.cmnd', $keyword);
		$this->db->or_like('giaovien.tengv', $keyword);
		$this->db->order_by('giaovien.id', 'DESC');
		$query = $this->db->get();
			
		if ($query->num_rows() > 0)
		{
			$result = $query->result_array();
			return $result;
		}
	}

	public function count_all_giaovien()
	{
		$this->db->select('id');
		$this->db->from('giaovien');
		return $this->db->count_all_results();
	}
}
// END giaovien_model.php
/* Location: ./application/models/giaovien_model.php */
